package com.xtianzhuang.www.service.base;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import com.xtianzhuang.www.entity.subject.UserSubject;
import com.xtianzhuang.www.utils.LunarUtil;
import com.xtianzhuang.www.utils.SingletonFactory;

import flexjson.JSONSerializer;


@Service("baseServiceBiz")
public class BaseServiceBiz
 {
	// 当前登录主体，可获取用户身份信息、权限信息等
	protected final static UserSubject subject = SingletonFactory.getInstance(UserSubject.class);

	protected Logger logger = Logger.getLogger(getClass());
	protected final SimpleDateFormat chineseDateFormat = new SimpleDateFormat("yyyy年MM月dd日");
	protected final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
	/**
	 * 打印json对象参数
	 * @param obj
	 */
	public void debugObject(Object obj) {
		if (logger.isDebugEnabled()) {
			String out = new JSONSerializer().exclude("*.class").exclude("password").exclude("loginPassowrd")
					.exclude("theOldPassword").exclude("newpwd").exclude("theNewPassword").deepSerialize(obj);
			logger.debug("\n" + out);
		}
	}


	public String getBirthDayByIdNo(String idNo) {
		// TODO Auto-generated method stub
		// 320681199407195011 >>> 1994-07-19
		StringBuffer stringBuffer = new StringBuffer();
		stringBuffer.append(idNo.substring(6, 10)).append("-").append(idNo.substring(10, 12)).append("-")
				.append(idNo.substring(12, 14));
		return stringBuffer.toString();
	}

	public String getBirthDayYingLByYangL(String idNo) {
		// TODO Auto-generated method stub
		String d = idNo.substring(6, 14);
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd");
		Calendar today = Calendar.getInstance();
		try {
			today.setTime(simpleDateFormat.parse(d));
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		LunarUtil lunar = new LunarUtil(today);
		return lunar.toString();
	}

}
